package com.xpqh.ksg.modular.overseas.controller;

import com.xpqh.ksg.base.BaseController;
import com.xpqh.ksg.base.BaseResponseDTO;
import com.xpqh.ksg.common.enums.result.BizExceptionEnum;
import com.xpqh.ksg.modular.overseas.dto.KsgOverseasInfoSubmitReqDTO;
import com.xpqh.ksg.modular.overseas.service.IKsgService;
import common.utils.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "ksg/overseasInfoSubmit")
public class KsgOverseasInfoSubmitController extends BaseController {
    @Autowired
    private IKsgService ksgService;

    @RequestMapping(method = RequestMethod.POST)
    public BaseResponseDTO process(@Valid @RequestBody KsgOverseasInfoSubmitReqDTO req) throws Exception {


        String ip = ToolUtil.getIp(this.getHttpServletRequest());
        req.setIp(ip);
        if (ksgService.getIpCount(ip,0) < 3) {
            return renderResultOk(ksgService.overseasInfoSubmit(req));
        }else {
            return renderResultOk(BizExceptionEnum.IP_NUM);
        }
    }
}
